<?php 
require('./lib/init.php');
$art_id = $_GET['art_id'];

//查询出所有栏目
$sql = "select * from cat";
$cat = mGetAll($sql);

//检测文章id是否为数字
if (!is_numeric($art_id)) {
	error('栏目id不合法');
}
//检测是否存在这篇文章
$sql = "select count(*) from art where art_id=$art_id";
if (mGetOne($sql) == 0) {
	header("Location:index.php");
}

//查询出文章
$sql = "select lastup,title,content,pubtime,comm,pic,thumb,catname from art left join cat on art.cat_id = cat.cat_id where art_id = '$art_id' order by art_id desc";
$art = mGetRow($sql);

//如果post非空,证明有数据提交
if (!empty($_POST)) {
	$comm['art_id'] = $art_id;
	$comm['nick'] = $_POST['nick'];
	$comm['content'] = $_POST['content'];
	$comm['pubtime'] = time();
	$comm['ip'] = sprintf('%u',ip2long(getIp()));
	$comm['email'] = $_POST['email'];

	//插入的评论返回结果,如果为false,则发布失败
	$rs = mExec('comment',$comm);

	//每增加一条评论,art表的 comm字段+1
     $sql = 'update art set comm=comm+1 where art_id='.$art_id;
     mQuery($sql);

	//成功跳转到上个页面
	$ref = $_SERVER['HTTP_REFERER'];
	header("Location: $ref");
}
//取出所有评论
$sql = "select * from comment where art_id = '$art_id'";
$comment = mGetAll($sql);

include(ROOT.'/view/front/art.html');



 ?>